package com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.service.impl;

import com.jxdinfo.hussar.support.datasource.annotations.HussarDs;
import com.jxdinfo.hussar.platform.core.utils.HussarUtils;
import com.jxdinfo.hussar.support.exception.HussarException;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.service.Pxjhgllhx1Service;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.model.Pxjhgllhx1;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.dao.Pxjhgllhx1Mapper;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jxdinfo.hussar.workflow.manage.engine.TaskEngineService;
import com.jxdinfo.hussar.common.tfmodel.TfModelEnum;
import com.jxdinfo.hussar.common.security.BaseSecurityUtil;
import com.jxdinfo.hussar.support.transaction.core.annotation.HussarTransactional;
import com.jxdinfo.hussar.support.mp.base.query.generator.SingleTableQueryGenerator;
import com.jxdinfo.hussar.workflow.engine.response.BpmResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashMap;
import com.jxdinfo.hussar.support.mp.base.query.generator.superquery.SuperQueryGenerator;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.dto.Pxjhgllhx1Dto;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.dto.Pxjhgllhx1Pxjhgllhx1dataset1;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.model.Pxjhgllhx1Master;
import org.springframework.aop.framework.AopContext;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.dto.Pxjhgllhx1Pxjhgllhx1dataset2;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.dto.Pxjhgllhx1Pxjhgllhx1dataset3;
import java.util.ArrayList;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.service.Pxjhgllhx1MasterService;
import com.jxdinfo.hussar.workflow.engine.constant.BpmConstant;
import java.util.Map;
import com.jxdinfo.hussar.workflow.manage.engine.InstanceEngineService;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.dao.Pxjhgllhx1Mapper;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.service.PlanzitemService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.vo.Pxjhgllhx1PageVO;
import com.jxdinfo.hussar.platform.core.base.apiresult.ApiResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.model.Pxjhgllhx1;
import com.jxdinfo.hussar.platform.core.utils.StringUtil;
import com.jxdinfo.hussar.example.pxmk.pxjhgllhx1.model.Planzitem;
import com.alibaba.fastjson.JSONObject;
import java.util.Collections;

/**
 * 培训计划管理lhx1服务实现类
 */
@Service("pxmk.pxjhgllhx1.Pxjhgllhx1ServiceImpl")
@HussarDs("master")
public class Pxjhgllhx1ServiceImpl implements Pxjhgllhx1Service {

    private static final Logger logger = LoggerFactory.getLogger(Pxjhgllhx1ServiceImpl.class);

    private static final String RETURN_CODE = "0";

    @Autowired
    private Pxjhgllhx1MasterService pxjhgllhx1MasterService;

    @Autowired
    private PlanzitemService planzitemService;

    @Autowired
    private Pxjhgllhx1Mapper pxjhgllhx1Mapper;

    @Override
    public ApiResponse<Pxjhgllhx1PageVO> hussarQueryPage(Page<Pxjhgllhx1> page) {
        try {
            Page<Pxjhgllhx1> pager = new Page<>(page.getCurrent(), page.getSize());
            Map<String, String[]> parameterMap = new HashMap<>();
            String[] orderParameter = new String[1];
            if (page.orders() != null) {
                for (OrderItem orderItem : page.orders()) {
                    if (orderItem.isAsc()) {
                        orderParameter[0] = orderItem.getColumn() + ",asc;";
                    } else {
                        orderParameter[0] = orderItem.getColumn() + ",desc;";
                    }
                }
            }
            parameterMap.put("orderRule", orderParameter);
            Pxjhgllhx1PageVO pxjhgllhx1PageVO = new Pxjhgllhx1PageVO();
            // 查询条件构造器,将排序条件封装成QueryWrapper
            SingleTableQueryGenerator singleTableQueryGenerator = new SingleTableQueryGenerator();
            QueryWrapper<Pxjhgllhx1> queryWrapper = singleTableQueryGenerator.initQueryWrapper(new Pxjhgllhx1(), parameterMap);
            List<Pxjhgllhx1> list = pxjhgllhx1Mapper.hussarQueryPage(pager, queryWrapper);
            pxjhgllhx1PageVO.setData(list);
            pxjhgllhx1PageVO.setCount(pager.getTotal());
            pxjhgllhx1PageVO.setCode(RETURN_CODE);
            return ApiResponse.success(pxjhgllhx1PageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询异常");
        }
    }

    @Override
    public ApiResponse<Pxjhgllhx1PageVO> hussarQueryPage_order_custom(Page<Pxjhgllhx1> page) {
        try {
            Page<Pxjhgllhx1> pager = new Page<>(page.getCurrent(), page.getSize());
            Map<String, String[]> parameterMap = new HashMap<>();
            String[] orderParameter = new String[1];
            if (page.orders() != null) {
                for (OrderItem orderItem : page.orders()) {
                    if (orderItem.isAsc()) {
                        orderParameter[0] = orderItem.getColumn() + ",asc;";
                    } else {
                        orderParameter[0] = orderItem.getColumn() + ",desc;";
                    }
                }
            }
            parameterMap.put("orderRule", orderParameter);
            Pxjhgllhx1PageVO pxjhgllhx1PageVO = new Pxjhgllhx1PageVO();
            // 查询条件构造器,将排序条件封装成QueryWrapper
            SingleTableQueryGenerator singleTableQueryGenerator = new SingleTableQueryGenerator();
            QueryWrapper<Pxjhgllhx1> queryWrapper = singleTableQueryGenerator.initQueryWrapper(new Pxjhgllhx1(), parameterMap);
            List<Pxjhgllhx1> list = pxjhgllhx1Mapper.hussarQueryPage_order_custom(pager, queryWrapper);
            pxjhgllhx1PageVO.setData(list);
            pxjhgllhx1PageVO.setCount(pager.getTotal());
            pxjhgllhx1PageVO.setCode(RETURN_CODE);
            return ApiResponse.success(pxjhgllhx1PageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询异常");
        }
    }

    @Override
    public ApiResponse<Pxjhgllhx1PageVO> hussarQuery() {
        try {
            Pxjhgllhx1PageVO pxjhgllhx1PageVO = new Pxjhgllhx1PageVO();
            List<Pxjhgllhx1> list = pxjhgllhx1Mapper.hussarQuery();
            pxjhgllhx1PageVO.setData(list);
            if (HussarUtils.isNotEmpty(list)) {
                pxjhgllhx1PageVO.setCount((long) list.size());
            }
            pxjhgllhx1PageVO.setCode(RETURN_CODE);
            return ApiResponse.success(pxjhgllhx1PageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询异常");
        }
    }

    @Override
    public ApiResponse<Pxjhgllhx1> formQuery(String id) {
        try {
            return ApiResponse.success(pxjhgllhx1Mapper.formQuery(id));
        } catch (Exception e) {
            throw new HussarException(TfModelEnum.TF_FORM_QUERY_FAILED.getMessage());
        }
    }

    @Override
    @HussarTransactional
    public ApiResponse<String> insertOrUpdate(Pxjhgllhx1 pxjhgllhx1) {
        try {
            Pxjhgllhx1Master pxjhgllhx1Master = pxjhgllhx1.gainPxjhgllhx1Master();
            pxjhgllhx1MasterService.saveOrUpdate(pxjhgllhx1Master);
            LambdaQueryWrapper<Planzitem> ew0 = new LambdaQueryWrapper<>();
            ew0.eq(Planzitem::getBusinessId, pxjhgllhx1Master.getBusinessId());
            planzitemService.remove(ew0);
            List<Planzitem> planzitems = pxjhgllhx1.gainPlanzitemArray();
            if (null != planzitems) {
                for (Planzitem planzitem : planzitems) {
                    planzitem.setBusinessId(pxjhgllhx1Master.getBusinessId());
                }
                planzitemService.saveOrUpdateBatch(planzitems);
            }
            return ApiResponse.success(String.valueOf(pxjhgllhx1Master.getBusinessId()), "");
        } catch (Exception e) {
            throw new HussarException(e.getMessage());
        }
    }

    @Override
    @HussarTransactional
    public ApiResponse<String> flowFormSubmit(Pxjhgllhx1Dto pxjhgllhx1Dto) {
        Pxjhgllhx1 pxjhgllhx1 = pxjhgllhx1Dto.getFormdata();
        String businessId = "";
        try {
            Pxjhgllhx1Master pxjhgllhx1Master = pxjhgllhx1.gainPxjhgllhx1Master();
            pxjhgllhx1MasterService.saveOrUpdate(pxjhgllhx1Master);
            LambdaQueryWrapper<Planzitem> ew0 = new LambdaQueryWrapper<>();
            ew0.eq(Planzitem::getBusinessId, pxjhgllhx1Master.getBusinessId());
            planzitemService.remove(ew0);
            List<Planzitem> planzitems = pxjhgllhx1.gainPlanzitemArray();
            if (null != planzitems) {
                for (Planzitem planzitem : planzitems) {
                    planzitem.setBusinessId(pxjhgllhx1Master.getBusinessId());
                }
                planzitemService.saveOrUpdateBatch(planzitems);
            }
            businessId = String.valueOf(pxjhgllhx1Master.getBusinessId());
        } catch (Exception e) {
            throw new HussarException(TfModelEnum.TF_SAVE_THE_FORM_EXCEPTION.getMessage());
        }
        ((Pxjhgllhx1Service) AopContext.currentProxy()).formsubmit(pxjhgllhx1Dto, businessId);
        return ApiResponse.success(businessId, TfModelEnum.TF_PROCESS_FORM_WAS_SUCCESSFULLY_SUBMITTED.getMessage());
    }

    @Override
    @HussarTransactional
    @HussarDs("master")
    public void formsubmit(Pxjhgllhx1Dto pxjhgllhx1Dto, String businessKey) {
        if (HussarUtils.isEmpty(BaseSecurityUtil.getUser())) {
            throw new HussarException(TfModelEnum.TF_FAILED_T0_OBTAIN_USER_INFORMATION.getMessage());
        }
        Map<String, String> appointMap = new HashMap<>();
        Map<String, Object> variable = new HashMap<>();
        String taskId = pxjhgllhx1Dto.getTaskId();
        String comment = pxjhgllhx1Dto.getComment();
        if (pxjhgllhx1Dto.getFlowSelect() == null) {
            appointMap.put(BpmConstant.STATIC_APPOINT_ASSIGNEE, pxjhgllhx1Dto.getParticipantSelect());
        } else {
            appointMap.put(pxjhgllhx1Dto.getFlowSelect(), pxjhgllhx1Dto.getParticipantSelect());
            variable.put(BpmConstant.BPM_NEXT_NODE, pxjhgllhx1Dto.getFlowSelect());
        }
        if (pxjhgllhx1Dto.getSelectBranches() != null) {
            List<String> nextNodeIds = new ArrayList<>();
            for (Map<String, String> map : pxjhgllhx1Dto.getSelectBranches()) {
                appointMap.put(map.get("flowSelect"), map.get("participants"));
                nextNodeIds.add(map.get("flowSelect"));
            }
            variable.put(BpmConstant.BPM_NEXT_NODE, String.join(",", nextNodeIds));
        }
        // 判断是否设置会签
        if (pxjhgllhx1Dto.getMultiType() != null) {
            variable.put(BpmConstant.MULTI_TYPE, pxjhgllhx1Dto.getMultiType());
            variable.put(BpmConstant.MULTI_FINISH_CONDITION, pxjhgllhx1Dto.getMultiFinishCondition());
        }
        if (pxjhgllhx1Dto.getNodeParticipantSelect() != null) {
            variable.put(BpmConstant.PUBLIC_APPOINT_ASSIGNEE, pxjhgllhx1Dto.getNodeParticipantSelect());
        }
        String processDefinitionKey = pxjhgllhx1Dto.getProcessDefinitionKey();
        String userId = String.valueOf(BaseSecurityUtil.getUser().getId());
        if (HussarUtils.isEmpty(taskId)) {
            BpmResponseResult startResult = InstanceEngineService.startProcessInstanceByKey(processDefinitionKey, userId, businessKey, variable);
            if (BpmConstant.SUCCESS_CODE.equals(startResult.getCode())) {
                taskId = (String) startResult.getResult().getJSONObject(0).get("taskId");
            } else {
                throw new HussarException(startResult.getMsg());
            }
        }
        BpmResponseResult bpmResponseResult = TaskEngineService.completeTask(taskId, userId, appointMap, null, comment, variable);
        if (!BpmConstant.SUCCESS_CODE.equals(bpmResponseResult.getCode())) {
            throw new HussarException(bpmResponseResult.getMsg());
        }
    }

    @Override
    @HussarTransactional
    public ApiResponse<String> flowFormSubmitReject(Pxjhgllhx1Dto pxjhgllhx1Dto) {
        Pxjhgllhx1 pxjhgllhx1 = pxjhgllhx1Dto.getFormdata();
        try {
            Pxjhgllhx1Master pxjhgllhx1Master = pxjhgllhx1.gainPxjhgllhx1Master();
            pxjhgllhx1MasterService.saveOrUpdate(pxjhgllhx1Master);
            LambdaQueryWrapper<Planzitem> ew0 = new LambdaQueryWrapper<>();
            ew0.eq(Planzitem::getBusinessId, pxjhgllhx1Master.getBusinessId());
            planzitemService.remove(ew0);
            List<Planzitem> planzitems = pxjhgllhx1.gainPlanzitemArray();
            if (null != planzitems) {
                for (Planzitem planzitem : planzitems) {
                    planzitem.setBusinessId(pxjhgllhx1Master.getBusinessId());
                }
                planzitemService.saveOrUpdateBatch(planzitems);
            }
            String returnCode = ((Pxjhgllhx1Service) AopContext.currentProxy()).formsubmitreject(pxjhgllhx1Dto, String.valueOf(pxjhgllhx1Master.getBusinessId()));
            if (BpmConstant.SUCCESS_CODE.equals(returnCode)) {
                return ApiResponse.success(TfModelEnum.TF_PROCESS_FORM_WAS_SUCCESSFULLY_SUBMITTED.getMessage());
            } else {
                throw new HussarException(TfModelEnum.TF_FAILED_TO_SUBMIT_THE_PROCESS_FORM.getMessage());
            }
        } catch (Exception e) {
            throw new HussarException(e.getMessage());
        }
    }

    @Override
    @HussarTransactional
    @HussarDs("master")
    public String formsubmitreject(Pxjhgllhx1Dto pxjhgllhx1Dto, String businessKey) {
        Map<String, String> appointMap = new HashMap<>();
        Map<String, Object> variable = new HashMap<>();
        try {
            if (HussarUtils.isEmpty(BaseSecurityUtil.getUser())) {
                throw new HussarException(TfModelEnum.TF_FAILED_T0_OBTAIN_USER_INFORMATION.getMessage());
            }
            String taskId = pxjhgllhx1Dto.getTaskId();
            String comment = pxjhgllhx1Dto.getComment();
            if (pxjhgllhx1Dto.getFlowSelect() == null) {
                appointMap.put(BpmConstant.STATIC_APPOINT_ASSIGNEE, pxjhgllhx1Dto.getParticipantSelect());
            } else {
                appointMap.put(pxjhgllhx1Dto.getFlowSelect(), pxjhgllhx1Dto.getParticipantSelect());
                variable.put(BpmConstant.BPM_NEXT_NODE, pxjhgllhx1Dto.getFlowSelect());
            }
            if (pxjhgllhx1Dto.getSelectBranches() != null) {
                List<String> nextNodeIds = new ArrayList<>();
                for (Map<String, String> map : pxjhgllhx1Dto.getSelectBranches()) {
                    appointMap.put(map.get("flowSelect"), map.get("participants"));
                    nextNodeIds.add(map.get("flowSelect"));
                }
                variable.put(BpmConstant.BPM_NEXT_NODE, String.join(",", nextNodeIds));
            }
            // 判断是否设置会签
            if (pxjhgllhx1Dto.getMultiType() != null) {
                variable.put(BpmConstant.MULTI_TYPE, pxjhgllhx1Dto.getMultiType());
                variable.put(BpmConstant.MULTI_FINISH_CONDITION, pxjhgllhx1Dto.getMultiFinishCondition());
            }
            String processDefinitionKey = pxjhgllhx1Dto.getProcessDefinitionKey();
            String userId = String.valueOf(BaseSecurityUtil.getUser().getId());
            if (HussarUtils.isEmpty(taskId)) {
                BpmResponseResult startResult;
                startResult = InstanceEngineService.startProcessInstanceByKey(processDefinitionKey, userId, businessKey, null);
                if (BpmConstant.SUCCESS_CODE.equals(startResult.getCode())) {
                    taskId = (String) startResult.getResult().getJSONObject(0).get("taskId");
                } else {
                    throw new HussarException(TfModelEnum.TF_FAILED_TO_CREATE_A_START_NODE.getMessage());
                }
            }
            BpmResponseResult bpmResponseResult = TaskEngineService.completeLeapTask(taskId, userId, appointMap, null, comment, variable);
            return bpmResponseResult.getCode();
        } catch (Exception e) {
            throw new HussarException(e.getMessage());
        }
    }

    @Override
    @HussarTransactional
    public ApiResponse<String> flowTableDelete(String id) {
        try {
            // 调用操作业务数据的方法
            if (StringUtil.isNotBlank(id)) {
                List<String> idList = Collections.singletonList(id);
                planzitemService.remove(Wrappers.<Planzitem>lambdaUpdate().in(Planzitem::getBusinessId, idList));
                pxjhgllhx1MasterService.removeByIds(idList);
            }
            return ((Pxjhgllhx1Service) AopContext.currentProxy()).deleteProcessInstance(id);
        } catch (Exception e) {
            throw new HussarException(e.getMessage());
        }
    }

    @Override
    @HussarTransactional
    public ApiResponse<String> flowTableDeleteUnStart(String id) {
        // 验证流程状态
        BpmResponseResult validateResult;
        try {
            validateResult = ((Pxjhgllhx1Service) AopContext.currentProxy()).getValidateResult(id);
            if (BpmConstant.SUCCESS_CODE.equals(validateResult.getCode())) {
                String state = validateResult.getResult().get(0) == null ? "" : validateResult.getResult().get(0).toString();
                switch(state) {
                    // 1 代表流程已经启动，并且节点处于第一节点，可以删除业务数据和流程数据
                    case BpmConstant.SUCCESS_CODE:
                        // 删除业务数据
                        if (StringUtil.isNotBlank(id)) {
                            List<String> idList = Collections.singletonList(id);
                            planzitemService.remove(Wrappers.<Planzitem>lambdaUpdate().in(Planzitem::getBusinessId, idList));
                            pxjhgllhx1MasterService.removeByIds(idList);
                        }
                        // 删除流程数据
                        return ((Pxjhgllhx1Service) AopContext.currentProxy()).deleteProcessInstance(id);
                    // 2 代表流程已经启动，并且节点不处于第一节点，不可以删除业务数据和流程数据
                    case "2":
                        throw new HussarException(validateResult.getMsg());
                    // 0 代表流程没有启动，可以删除业务数据，不需要删除流程数据
                    case "0":
                        // 删除业务数据
                        if (StringUtil.isNotBlank(id)) {
                            List<String> idList = Collections.singletonList(id);
                            planzitemService.remove(Wrappers.<Planzitem>lambdaUpdate().in(Planzitem::getBusinessId, idList));
                            pxjhgllhx1MasterService.removeByIds(idList);
                        }
                        return ApiResponse.success("");
                    default:
                        throw new HussarException(TfModelEnum.TF_DELETION_FAILED.getMessage());
                }
            }
            throw new HussarException(TfModelEnum.TF_DELETION_FAILED.getMessage());
        } catch (Exception e) {
            throw new HussarException(e.getMessage());
        }
    }

    @Override
    @HussarTransactional
    @HussarDs("master")
    public BpmResponseResult getValidateResult(String id) {
        return InstanceEngineService.validateDeleteByBusinessKey(String.valueOf(id));
    }

    @Override
    @HussarTransactional
    @HussarDs("master")
    public ApiResponse<String> deleteProcessInstance(String id) {
        BpmResponseResult bpmResponseResult;
        try {
            bpmResponseResult = InstanceEngineService.deleteProcessInstanceByBusinessKey(String.valueOf(id));
            if (BpmConstant.SUCCESS_CODE.equals(bpmResponseResult.getCode())) {
                return ApiResponse.success("");
            }
            throw new HussarException(bpmResponseResult.getMsg());
        } catch (Exception e) {
            throw new HussarException(e.getMessage());
        }
    }

    @Override
    @HussarTransactional
    @HussarDs("master")
    public ApiResponse<JSONObject> flowTableUpdate(Pxjhgllhx1Dto pxjhgllhx1Dto) {
        try {
            return InstanceEngineService.validateEditAuthority(pxjhgllhx1Dto.getUpdateRowId());
        } catch (Exception e) {
            throw new HussarException(TfModelEnum.TF_PROCESS_TABLE_IS_ABNORMALLY_MODIFIED.getMessage() + e.getMessage());
        }
    }

    @Override
    public ApiResponse<Pxjhgllhx1PageVO> hussarQuerypxjhgllhx1Condition_1Page(Pxjhgllhx1Pxjhgllhx1dataset1 pxjhgllhx1dataset1) {
        try {
            Pxjhgllhx1PageVO pxjhgllhx1PageVO = new Pxjhgllhx1PageVO();
            Page<Pxjhgllhx1> pager = new Page<>(pxjhgllhx1dataset1.getCurrent(), pxjhgllhx1dataset1.getSize());
            Map<String, String[]> parameterMap = new HashMap<>();
            String[] orderParameter = new String[1];
            if (pxjhgllhx1dataset1.getOrders() != null) {
                for (OrderItem orderItem : pxjhgllhx1dataset1.getOrders()) {
                    if (orderItem.isAsc()) {
                        orderParameter[0] = orderItem.getColumn() + ",asc;";
                    } else {
                        orderParameter[0] = orderItem.getColumn() + ",desc;";
                    }
                }
            }
            parameterMap.put("orderRule", orderParameter);
            pxjhgllhx1dataset1.setPxjhgllhx1PlansubmiterFullLike(pxjhgllhx1dataset1.getPxjhgllhx1PlansubmiterFullLike().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            pxjhgllhx1dataset1.setPxjhgllhx1PlannameFullLike(pxjhgllhx1dataset1.getPxjhgllhx1PlannameFullLike().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            // 查询条件构造器,将排序条件封装成QueryWrapper
            SingleTableQueryGenerator singleTableQueryGenerator = new SingleTableQueryGenerator();
            QueryWrapper<Pxjhgllhx1> queryWrapper = singleTableQueryGenerator.initQueryWrapper(new Pxjhgllhx1(), parameterMap);
            List<Pxjhgllhx1> list = pxjhgllhx1Mapper.hussarQuerypxjhgllhx1Condition_1Page(pager, pxjhgllhx1dataset1, queryWrapper);
            pxjhgllhx1PageVO.setData(list);
            pxjhgllhx1PageVO.setCount(pager.getTotal());
            pxjhgllhx1PageVO.setCode(RETURN_CODE);
            return ApiResponse.success(pxjhgllhx1PageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询异常");
        }
    }

    @Override
    public ApiResponse<Pxjhgllhx1PageVO> hussarQuerypxjhgllhx1Condition_1Page_order_custom(Pxjhgllhx1Pxjhgllhx1dataset1 pxjhgllhx1dataset1) {
        try {
            Pxjhgllhx1PageVO pxjhgllhx1PageVO = new Pxjhgllhx1PageVO();
            Page<Pxjhgllhx1> pager = new Page<>(pxjhgllhx1dataset1.getCurrent(), pxjhgllhx1dataset1.getSize());
            Map<String, String[]> parameterMap = new HashMap<>();
            String[] orderParameter = new String[1];
            if (pxjhgllhx1dataset1.getOrders() != null) {
                for (OrderItem orderItem : pxjhgllhx1dataset1.getOrders()) {
                    if (orderItem.isAsc()) {
                        orderParameter[0] = orderItem.getColumn() + ",asc;";
                    } else {
                        orderParameter[0] = orderItem.getColumn() + ",desc;";
                    }
                }
            }
            parameterMap.put("orderRule", orderParameter);
            pxjhgllhx1dataset1.setPxjhgllhx1PlansubmiterFullLike(pxjhgllhx1dataset1.getPxjhgllhx1PlansubmiterFullLike().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            pxjhgllhx1dataset1.setPxjhgllhx1PlannameFullLike(pxjhgllhx1dataset1.getPxjhgllhx1PlannameFullLike().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            // 查询条件构造器,将排序条件封装成QueryWrapper
            SingleTableQueryGenerator singleTableQueryGenerator = new SingleTableQueryGenerator();
            QueryWrapper<Pxjhgllhx1> queryWrapper = singleTableQueryGenerator.initQueryWrapper(new Pxjhgllhx1(), parameterMap);
            List<Pxjhgllhx1> list = pxjhgllhx1Mapper.hussarQuerypxjhgllhx1Condition_1Page_order_custom(pager, pxjhgllhx1dataset1, queryWrapper);
            pxjhgllhx1PageVO.setData(list);
            pxjhgllhx1PageVO.setCount(pager.getTotal());
            pxjhgllhx1PageVO.setCode(RETURN_CODE);
            return ApiResponse.success(pxjhgllhx1PageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询异常");
        }
    }

    @Override
    public ApiResponse<Pxjhgllhx1PageVO> hussarQuerypxjhgllhx1Condition_2Page(Pxjhgllhx1Pxjhgllhx1dataset2 pxjhgllhx1dataset2) {
        try {
            Pxjhgllhx1PageVO pxjhgllhx1PageVO = new Pxjhgllhx1PageVO();
            Page<Pxjhgllhx1> pager = new Page<>(pxjhgllhx1dataset2.getCurrent(), pxjhgllhx1dataset2.getSize());
            Map<String, String[]> parameterMap = new HashMap<>();
            String[] orderParameter = new String[1];
            if (pxjhgllhx1dataset2.getOrders() != null) {
                for (OrderItem orderItem : pxjhgllhx1dataset2.getOrders()) {
                    if (orderItem.isAsc()) {
                        orderParameter[0] = orderItem.getColumn() + ",asc;";
                    } else {
                        orderParameter[0] = orderItem.getColumn() + ",desc;";
                    }
                }
            }
            parameterMap.put("orderRule", orderParameter);
            pxjhgllhx1dataset2.setPxjhgllhx1PlansubmiterFullLike(pxjhgllhx1dataset2.getPxjhgllhx1PlansubmiterFullLike().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            pxjhgllhx1dataset2.setPxjhgllhx1PlannameFullLike(pxjhgllhx1dataset2.getPxjhgllhx1PlannameFullLike().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            // 查询条件构造器,将排序条件封装成QueryWrapper
            SingleTableQueryGenerator singleTableQueryGenerator = new SingleTableQueryGenerator();
            QueryWrapper<Pxjhgllhx1> queryWrapper = singleTableQueryGenerator.initQueryWrapper(new Pxjhgllhx1(), parameterMap);
            List<Pxjhgllhx1> list = pxjhgllhx1Mapper.hussarQuerypxjhgllhx1Condition_2Page(pager, pxjhgllhx1dataset2, queryWrapper);
            pxjhgllhx1PageVO.setData(list);
            pxjhgllhx1PageVO.setCount(pager.getTotal());
            pxjhgllhx1PageVO.setCode(RETURN_CODE);
            return ApiResponse.success(pxjhgllhx1PageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询异常");
        }
    }

    @Override
    public ApiResponse<Pxjhgllhx1PageVO> hussarQuerypxjhgllhx1Condition_2Page_order_custom(Pxjhgllhx1Pxjhgllhx1dataset2 pxjhgllhx1dataset2) {
        try {
            Pxjhgllhx1PageVO pxjhgllhx1PageVO = new Pxjhgllhx1PageVO();
            Page<Pxjhgllhx1> pager = new Page<>(pxjhgllhx1dataset2.getCurrent(), pxjhgllhx1dataset2.getSize());
            Map<String, String[]> parameterMap = new HashMap<>();
            String[] orderParameter = new String[1];
            if (pxjhgllhx1dataset2.getOrders() != null) {
                for (OrderItem orderItem : pxjhgllhx1dataset2.getOrders()) {
                    if (orderItem.isAsc()) {
                        orderParameter[0] = orderItem.getColumn() + ",asc;";
                    } else {
                        orderParameter[0] = orderItem.getColumn() + ",desc;";
                    }
                }
            }
            parameterMap.put("orderRule", orderParameter);
            pxjhgllhx1dataset2.setPxjhgllhx1PlansubmiterFullLike(pxjhgllhx1dataset2.getPxjhgllhx1PlansubmiterFullLike().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            pxjhgllhx1dataset2.setPxjhgllhx1PlannameFullLike(pxjhgllhx1dataset2.getPxjhgllhx1PlannameFullLike().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            // 查询条件构造器,将排序条件封装成QueryWrapper
            SingleTableQueryGenerator singleTableQueryGenerator = new SingleTableQueryGenerator();
            QueryWrapper<Pxjhgllhx1> queryWrapper = singleTableQueryGenerator.initQueryWrapper(new Pxjhgllhx1(), parameterMap);
            List<Pxjhgllhx1> list = pxjhgllhx1Mapper.hussarQuerypxjhgllhx1Condition_2Page_order_custom(pager, pxjhgllhx1dataset2, queryWrapper);
            pxjhgllhx1PageVO.setData(list);
            pxjhgllhx1PageVO.setCount(pager.getTotal());
            pxjhgllhx1PageVO.setCode(RETURN_CODE);
            return ApiResponse.success(pxjhgllhx1PageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询异常");
        }
    }

    @Override
    public ApiResponse<Pxjhgllhx1PageVO> hussarQuerypxjhgllhx1Condition_3Page(Pxjhgllhx1Pxjhgllhx1dataset3 pxjhgllhx1dataset3) {
        try {
            Pxjhgllhx1PageVO pxjhgllhx1PageVO = new Pxjhgllhx1PageVO();
            Page<Pxjhgllhx1> pager = new Page<>(pxjhgllhx1dataset3.getCurrent(), pxjhgllhx1dataset3.getSize());
            Map<String, String[]> parameterMap = new HashMap<>();
            String[] orderParameter = new String[1];
            if (pxjhgllhx1dataset3.getOrders() != null) {
                for (OrderItem orderItem : pxjhgllhx1dataset3.getOrders()) {
                    if (orderItem.isAsc()) {
                        orderParameter[0] = orderItem.getColumn() + ",asc;";
                    } else {
                        orderParameter[0] = orderItem.getColumn() + ",desc;";
                    }
                }
            }
            parameterMap.put("orderRule", orderParameter);
            pxjhgllhx1dataset3.setPxjhgllhx1PlansubmiterFullLike1(pxjhgllhx1dataset3.getPxjhgllhx1PlansubmiterFullLike1().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            pxjhgllhx1dataset3.setPxjhgllhx1PlannameFullLike(pxjhgllhx1dataset3.getPxjhgllhx1PlannameFullLike().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            // 查询条件构造器,将排序条件封装成QueryWrapper
            SingleTableQueryGenerator singleTableQueryGenerator = new SingleTableQueryGenerator();
            QueryWrapper<Pxjhgllhx1> queryWrapper = singleTableQueryGenerator.initQueryWrapper(new Pxjhgllhx1(), parameterMap);
            List<Pxjhgllhx1> list = pxjhgllhx1Mapper.hussarQuerypxjhgllhx1Condition_3Page(pager, pxjhgllhx1dataset3, queryWrapper);
            pxjhgllhx1PageVO.setData(list);
            pxjhgllhx1PageVO.setCount(pager.getTotal());
            pxjhgllhx1PageVO.setCode(RETURN_CODE);
            return ApiResponse.success(pxjhgllhx1PageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询异常");
        }
    }

    @Override
    public ApiResponse<Pxjhgllhx1PageVO> hussarQuerypxjhgllhx1Condition_3Page_order_custom(Pxjhgllhx1Pxjhgllhx1dataset3 pxjhgllhx1dataset3) {
        try {
            Pxjhgllhx1PageVO pxjhgllhx1PageVO = new Pxjhgllhx1PageVO();
            Page<Pxjhgllhx1> pager = new Page<>(pxjhgllhx1dataset3.getCurrent(), pxjhgllhx1dataset3.getSize());
            Map<String, String[]> parameterMap = new HashMap<>();
            String[] orderParameter = new String[1];
            if (pxjhgllhx1dataset3.getOrders() != null) {
                for (OrderItem orderItem : pxjhgllhx1dataset3.getOrders()) {
                    if (orderItem.isAsc()) {
                        orderParameter[0] = orderItem.getColumn() + ",asc;";
                    } else {
                        orderParameter[0] = orderItem.getColumn() + ",desc;";
                    }
                }
            }
            parameterMap.put("orderRule", orderParameter);
            pxjhgllhx1dataset3.setPxjhgllhx1PlansubmiterFullLike1(pxjhgllhx1dataset3.getPxjhgllhx1PlansubmiterFullLike1().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            pxjhgllhx1dataset3.setPxjhgllhx1PlannameFullLike(pxjhgllhx1dataset3.getPxjhgllhx1PlannameFullLike().replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_").replaceAll("\\[", "/[").replaceAll("]", "/]"));
            // 查询条件构造器,将排序条件封装成QueryWrapper
            SingleTableQueryGenerator singleTableQueryGenerator = new SingleTableQueryGenerator();
            QueryWrapper<Pxjhgllhx1> queryWrapper = singleTableQueryGenerator.initQueryWrapper(new Pxjhgllhx1(), parameterMap);
            List<Pxjhgllhx1> list = pxjhgllhx1Mapper.hussarQuerypxjhgllhx1Condition_3Page_order_custom(pager, pxjhgllhx1dataset3, queryWrapper);
            pxjhgllhx1PageVO.setData(list);
            pxjhgllhx1PageVO.setCount(pager.getTotal());
            pxjhgllhx1PageVO.setCode(RETURN_CODE);
            return ApiResponse.success(pxjhgllhx1PageVO);
        } catch (Exception e) {
            throw new HussarException("表格查询异常");
        }
    }
}
